﻿<%@ Page Language="C#" MasterPageFile="~/Back/BackgroundMain.master" AutoEventWireup="true"
    CodeFile="ImageList.aspx.cs" Inherits="Back_ImageList" Title="图片管理页面" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script type="text/javascript">
       // var selNum = 0;           
        function AddSelValues(oChk)  
        { 
            var iphdn = document.getElementById("ctl00_ContentPlaceHolder1_ipt_HdnSelectedValues");                 
            if(oChk.checked)
            {
            //    selNum++;
                iphdn.value += "," + oChk.value; 
            }
            else
            {
              iphdn.value = iphdn.value.replace("," + oChk.value,""); 
            }
        }
        
        function countInstances(mainStr, subStr)
        {
            var count = 0;
            var offset = 0;
            do
            {
                offset = mainStr.indexOf(subStr, offset);
                if(offset != -1)
                {
                    count++;
                    offset += subStr.length;
                }
            }while(offset != -1)
            return count;
        }

        function checknum()
        {     
            var iphdn = document.getElementById("ctl00_ContentPlaceHolder1_ipt_HdnSelectedValues");      
            var dlltype = document.getElementById("ctl00_ContentPlaceHolder1_ddlImageType");
            //var num = iphdn.value.split(",").length;
            var  index   =   dlltype.selectedIndex; 
            var  val   =   dlltype.options[index].value;
            var num = countInstances(iphdn.value, ",");
            if(val == "PPT" &&  num > 5)
            {
                alert("操作失败，显示主页幻灯图片不能超过五张");
                return false;
            }   
            else if(val == "TPXW" &&  num > 5)
            {
                alert("操作失败，显示图片新闻图片不能超过五张");
                return false;
            }
            else if(val == "STA" &&  num > 1)
            {
                alert("操作失败，显示上部专题图片不能超过一张");
                return false;
            }
            else if(val == "STB" &&  num > 1)
            {
                alert("操作失败，显示中部专题图片不能超过一张");
                return false;
            }
            else if(val == "STC" &&  num > 3)
            {
                alert("操作失败，显示底部专题图片不能超过三张");
                return false;
            }
            return true;
        }
        
        

    </script>


    <asp:ScriptManager runat="server" ID="Script1">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>    
        <input id="ipt_HdnSelectedValues"  type="hidden" name="HdnSelectedValues" runat="server" />
            <div class="centertop" id="dvNav" runat="server">
                当前位置：<a href="BgArticleList.aspx">中共重庆市沙坪坝区委统一战线工作部</a>&nbsp;>>&nbsp;<a href="ImageList.aspx">图片管理</a></div>
            <div style="text-align: left; padding-top: 5px; padding-bottom: 5px; padding-left: 25px">
                图片类型：
                <asp:DropDownList ID="ddlImageType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlImageType_SelectedIndexChanged">
                    <asp:ListItem Text="主页幻灯图片" Value="PPT"></asp:ListItem>
                    <asp:ListItem Text="图片新闻图片" Value="TPXW"></asp:ListItem>
                    <asp:ListItem Text="上部专题图片" Value="STA"></asp:ListItem>
                    <asp:ListItem Text="中部专题图片" Value="STB"></asp:ListItem>
                    <asp:ListItem Text="底部专题图片" Value="STC"></asp:ListItem>
                </asp:DropDownList>
            </div>
            <div>
                <asp:GridView ID="gvDict" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                    OnRowCommand="gvDict_RowCommand" PageSize="3" Width="650px" 
                    CellPadding="4" ForeColor="#333333"
                    GridLines="None" OnPageIndexChanging="gvDict_PageIndexChanging" 
                    onrowdatabound="gvDict_RowDataBound">
                    <EmptyDataTemplate>
                        暂时没有您需要的数据!
                    </EmptyDataTemplate>
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:Label ID="lbl_ID" runat="server" Text='<%#Eval("ID")%>' Visible="false"></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="是否显示">
                            <HeaderStyle HorizontalAlign="center" Width="60px" />
                            <ItemStyle HorizontalAlign="center" />
                            <ItemTemplate>
                              <input type="checkbox" runat="server" id="IsDisplayCheckBox" onclick="AddSelValues(this)"
     value='<%#DataBinder.Eval(Container.DataItem,"ID")%>'/>                               
                            </ItemTemplate>
                        </asp:TemplateField>
                        
                        <asp:TemplateField HeaderText="标题">
                            <HeaderStyle HorizontalAlign="center" />
                            <ItemStyle Width="100px" HorizontalAlign="left" />
                            <ItemTemplate>
                                <%#Eval("Title")%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="图片">
                            <HeaderStyle HorizontalAlign="center" Width="400px" />
                            <ItemStyle Width="400px" HorizontalAlign="center" />
                            <ItemTemplate>
                                <div style="width: 400px; overflow: auto">
                                    <img src='../imagesUpload/<%#Eval("ImageURL")%>' height="82px" alt="" /></div>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="链接地址" Visible="false">
                            <HeaderStyle HorizontalAlign="left" />
                            <ItemStyle HorizontalAlign="left" />
                            <ItemTemplate>
                                <%#Eval("LinkURL")%>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="操作">
                            <HeaderStyle Width="60px" />
                            <ItemTemplate>
                                <asp:LinkButton ID="lnkbDelete" runat="server" CommandArgument='<%# Eval("ID") %>'
                                    CommandName="DeleteContent" OnClientClick="return confirm('是否删除这个图片?')" Text="删除"></asp:LinkButton>
                                <a href='EditImage.aspx?ID=<%#Eval("ID")%>' target="_self">修改</a>
                            </ItemTemplate>
                        </asp:TemplateField>
                       
                    </Columns>
                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#2461BF" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
                <div style="text-align: right; padding-top: 10px; padding-right: 22px">
                    <asp:Button ID="btn_sumit" runat="server" Text="提交" OnClientClick="return checknum();" OnClick="btn_sumit_Click" CssClass="button" />
                    <asp:Button ID="btn_Add" runat="server" PostBackUrl="~/Back/BgPicAdd.aspx" Text="添加图片"
                        CssClass="button" />
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
